//
//  FlyRefreshHeader.m
//  PartyBuildingCloud
//
//  Created by lifayu on 16/9/22.
//  Copyright © 2016年 贵阳飞云科技有限公司. All rights reserved.
//

#import "FlyRefreshHeader.h"

@interface FlyRefreshHeader ()

@property (weak, nonatomic) UIImageView *animateImages;

@end


@implementation FlyRefreshHeader

#pragma mark - 重写方法
#pragma mark 在这里做一些初始化配置（比如添加子控件）
- (void)prepare
{
    [super prepare];
    
    // 设置控件的高度
    self.mj_h = 48;
    NSMutableArray *refreshingImages = [NSMutableArray array];
    for (int i = 1; i <= 8; i++)
    {
        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"loading%i", i]];
        [refreshingImages addObject:image];
    }
    UIImage *image = [refreshingImages firstObject];
    UIImageView *imageViews = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, image.size.width, image.size.height)];
    
    imageViews.animationImages = refreshingImages;
    imageViews.animationDuration = 0.8;
    [self addSubview:imageViews];
    
    self.animateImages = imageViews;
}


#pragma mark 在这里设置子控件的位置和尺寸
- (void)placeSubviews
{
    [super placeSubviews];
    self.animateImages.frame = CGRectMake(self.frame.size.width/2 - self.animateImages.frame.size.width/2, self.frame.size.height/2 - self.animateImages.frame.size.height/2, self.animateImages.frame.size.width, self.animateImages.frame.size.height);
}


#pragma mark 监听scrollView的contentOffset改变
- (void)scrollViewContentOffsetDidChange:(NSDictionary *)change
{
    [super scrollViewContentOffsetDidChange:change];
    
}

#pragma mark 监听scrollView的contentSize改变
- (void)scrollViewContentSizeDidChange:(NSDictionary *)change
{
    [super scrollViewContentSizeDidChange:change];
    
}

#pragma mark 监听scrollView的拖拽状态改变
- (void)scrollViewPanStateDidChange:(NSDictionary *)change
{
    [super scrollViewPanStateDidChange:change];
    
}

#pragma mark 监听控件的刷新状态
- (void)setState:(MJRefreshState)state
{
    MJRefreshCheckState;
    
    switch (state) {
        case MJRefreshStateIdle:
            [self.animateImages stopAnimating];
            break;
        case MJRefreshStatePulling:
        case MJRefreshStateRefreshing:
        case MJRefreshStateWillRefresh:
            [self.animateImages startAnimating];
            break;
        default:
            break;
    }
}



@end
